$.namespace('oa.workOrderDistribute');

oa.workOrderDistribute = function(){
	return {
		init : function(){
			EasyUIInit.initLayout({
				captionWidth : 100,
				fieldWidth : 200,
				fieldHeight : 30,
				rowHeight : 40,
				columns : 2,
				controls : this.config.fm
			}, 'fm');
			this.loadData();
		},
		loadData : function(){
			// 流程数据
			$('#taskId').val(getParameter('act.taskId'));
			$('#procInsId').val(getParameter('act.procInsId'));
			// 业务数据回显
			$.ajax({
				type : 'GET',
				url : ctxRest + '/oa/workorder/get?id=' + getParameter('id'),
				contentType : 'application/json;charset=UTF-8',
				beforeSend : function(){ progressLoad();},
				success : function(result){//console.log(JSON.stringify(result));
					progressClose();
					$('#id').val(result.id);
					EasyUIInit.loadData("fm", result);
					$('#score').numberbox("setValue", result.score);
					// 图片回显
					if(result.pic){
						var pics = result.pic.split(',');
						for (var i = 0;i < pics.length;i++) {
							if (pics[i]) {
								$('#pics').append('<a target="_blank" style="float:left;margin-right:5px;" href="' + ctxRest + '/sys/file/get?path=' + pics[i] + '"><img src="' + ctxRest + '/sys/file/get?path=' + pics[i] + '" style="width:100px;height:100px;"/></a>');
							}
						}
					}
				}
			});
		},
		getFormData : function(){
			var obj;
			var fm = $('#fm');
			if (fm.form('validate')) {
				obj = $.serializeObject(fm);
				obj.paramMap = {
					dept : obj.dept
				};
				obj.act = {
					taskId : obj.taskId,
					procInsId : obj.procInsId
				};
				delete obj.dept;
				delete obj.taskId;
				delete obj.procInsId;
			}
			return obj;
		},
		distribute : function() {
			var obj = this.getFormData();//console.log(JSON.stringify(obj));return;
			if(obj) {
				$.messager.confirm('提示', '您确定要派发至该部门？', function(flag){
					if (flag) {
						$.ajax({
							type : 'POST',
							url	 : ctxRest + '/oa/workorder/distribute',
							contentType : 'application/json;charset=utf-8',
							data : JSON.stringify(obj),
							beforeSend : function(){ progressLoad(); },
							success : function(result){
								progressClose();
								if (result && result.errcode == 0) {
									$.messager.alert('提示', '派发成功.', 'info');
									window.location.href = ctx + '/page/act/taskTodoList';
								}
							}
						})
					}
				});
			}
		}
	}
}();

oa.workOrderDistribute.config = {
	fm : [
		{id:'taskId',type:'input',isExternal:true,attr:'hidden=true',colspan:0},
		{id:'procInsId',type:'input',isExternal:true,attr:'hidden=true',colspan:0},
		{id:'id',type:'input',isExternal:true,attr:'hidden=true',colspan:0},
		{id:'gridName',caption:'广场名称：',type:'span',isExternal:true},
		{id:'regionName',caption:'广场区域：',type:'span',isExternal:true},
		{id:'scoreTypeName',caption:'检查项目：',type:'span',isExternal:true},
		//{id:'score',caption:'考核扣分：',type:'span',isExternal:true},
		{id:'score',caption:'考核扣分',type:'easyui-numberbox',option:{required:true,min:0,max:100,precision:2}},
		{id:'sourceName',caption:'案件来源：',type:'span',isExternal:true},
		//{id:'typeName',caption:'工单类型：',type:'span',isExternal:true},
		//{id:'facilityName',caption:'设施：',type:'span',isExternal:true,colspan:2} ,
		//{id:'gridName',caption:'广场：',type:'span',isExternal:true},
		//{id:'regionName',caption:'区域：',type:'span',isExternal:true},
		{id:'createTime',caption:'工单时间：',type:'span',isExternal:true},
		{id:'limitHour',caption:'期限(小时)：',type:'span',isExternal:true},
		{id:'content',caption:'内容：',type:'span',isExternal:true,colspan:2},
		{id:'pics',caption:'工单图片：',type:'div',isExternal:true,colspan:2},
		{id:'dept',caption:'派发部门：',type:'easyui-combotree',option:{
				url : ctxRest + '/sys/department/list',
				idFiled : 'id',
				textFiled : 'name',
				parentField : 'parentId',
				lines : true,
				editable:false,
				required:true
			}
		},
		{id:'div_button',caption:'',captionVisible:true,type:'span',colspan:2,isExternal:true,style:'text-align: center',
			controls:[
	          	{id:'lb_ok',caption:'',captionVisible:false,type:'easyui-linkbutton',style:'padding:2px',attr:'onClick="oa.workOrderDistribute.distribute()"',option:{text:"确定",width:80}},
	          ]	
		}
	]
}

$(function(){
	oa.workOrderDistribute.init();
})